package com.zerocode.smarttravel

import android.graphics.Color
import android.util.TypedValue
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentStatePagerAdapter
import com.zerocode.smarttravel.base.BaseActivity
import com.zerocode.smarttravel.databinding.ActivityMainBinding
import com.zerocode.smarttravel.ui.*

/**
 *  mvc  mvp  mvvm
 * @author YSJ
 * @date 2021/7/12 : 20:56
 */
class MainActivity : BaseActivity<ActivityMainBinding>() {


    override fun getViews(): Int = R.layout.activity_main

    private val array = arrayListOf<Fragment>(
        HomeFragment(),
        DestinationFragment(),
        CustomizationFragment(),
        FindFragment(),
        MyFragment()
    )

    private val arrayStr = arrayOf(
        "首页",
        "目的地",
        "定制",
        "发现",
        "我的"
    )


    override fun initData() {

        // 状态栏初始化
        changeStatusBarColor(Color.TRANSPARENT, false)

        // 初始化viewModel
        binding?.viewModel = MainActivityViewModel()

        // 初始化fragment
        initFragment()
    }

    private fun initFragment() {

        // 设置适配器
        binding?.mainView?.adapter = object :
            FragmentStatePagerAdapter(
                supportFragmentManager,
                BEHAVIOR_SET_USER_VISIBLE_HINT
            ) {

            override fun getItem(position: Int): Fragment {
                return array[position]
            }

            override fun getCount(): Int = array.size
        }

//        binding?.mainView?.offscreenPageLimit=array.size

        binding?.mainBottomNavigation?.binding(binding?.mainView)
            ?.setTextViewChildTextFromString(arrayStr)
            // 设置选中时的图片
            ?.setSelectTextViewChildImageFromResource(
                intArrayOf(
                    R.mipmap.yz_icon_home_selected,
                    R.mipmap.yz_icon_discover_selected,
                    R.mipmap.yz_icon_message_selected,
                    R.mipmap.yz_icon_message_selected,
                    R.mipmap.yz_icon_aboutme_selected
                )
            )
            // 设置未选中时的图片
            ?.setUnselectTextViewChildImageFromResource(
                intArrayOf(
                    R.mipmap.yz_icon_home_unselected,
                    R.mipmap.yz_icon_discover_unselected,
                    R.mipmap.yz_icon_message_unselected,
                    R.mipmap.yz_icon_message_unselected,
                    R.mipmap.yz_icon_aboutme_unselected
                )
            )

            // 设置字体大小
            ?.setTextSize(10f, TypedValue.COMPLEX_UNIT_DIP)
            // 设置选中颜色
            ?.setSelectTextColor(Color.RED)
            // 设置未选中的颜色
            ?.setUnSelectTextColor(R.color.color_999999)?.commit()

    }

    override fun initEvent() {

    }


}